package com.heima.jopo.servlet;

import com.heima.jopo.obj.UserInfo;
import com.heima.jopo.web.LoginVerify;
import com.heima.jopo.web.SeleList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "login", urlPatterns = "/loginSer")
public class LoginServlet extends HttpServlet {


    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String id = request.getParameter("id");
        String psss = request.getParameter("pwd");

        try {
            LoginVerify lo=new LoginVerify();
            //判断账户密码是否正确的方法
            lo.loginVer(id,psss);

                //如果账户密码正确 把数据对象传到主页
            SeleList se=new SeleList();
            //查询所有的对象信息 封装到对象集合中
            List<UserInfo> listuser = se.selectUserinfo();

            //创建Session
            HttpSession session = request.getSession();
            session.setAttribute("seleUser",listuser);

            response.sendRedirect("main.jsp");
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
